import { CopyControllerBase } from "./CopyControllerBase";
import { DominionWarResultWin } from "../../dominionWar/DominionWarResultWin";
import { IView } from "../../../../mvc/interfaces/IView";
import { DominionWarCopyInfoPanel } from "../dominionWar/DominionWarCopyInfoPanel";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../../../Message/Command/EPublicCommand";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
import { SDominionRefreshBoss } from "../../../../../Message/Public/SDominionRefreshBoss";
import { SDominionBossInfoList } from "../../../../../Message/Public/SDominionBossInfoList";
import { SDominionMyResult } from "../../../../../Message/Public/SDominionMyResult";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
type int = number;
//class DominionWarCopyController
    
    export  class DominionWarCopyController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */get myResultWin(): DominionWarResultWin
        {
            if (!this._myResultWin) 
            {
                this._myResultWin = new DominionWarResultWin();
            }
            return this._myResultWin;
        }

        protected /* override */ initView(): IView
        {
            if (!this._view) 
            {
                this._view = new DominionWarCopyInfoPanel();
            }
            return this._view;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionMyResult, this.onMyResultReceive);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionUpdateBossInfo, this.onUpdateBossInfo);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionRefreshBoss, this.onBossRefresh);
            return;
        }

        /* internal  */onBossRefresh(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDominionRefreshBoss;
            if (loc1.statues == 1) 
            {
                this._isBossInfoUp = true;
                (this.view as DominionWarCopyInfoPanel).updateInfos({"msg": loc1});
            }
            return;
        }

        /* internal  */onUpdateBossInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDominionBossInfoList;
            if (loc1.bossInfos.length >= 6) 
            {
                this._isBossInfoUp = true;
                (this.view as DominionWarCopyInfoPanel).updateInfos({"msg": loc1});
            }
            return;
        }

        /* internal  */onMyResultReceive(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDominionMyResult;
            this.myResultWin.show();
            this.myResultWin.update(loc1);
            return;
        }

        /* internal  */onComfirm(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuitCopy));
            }
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.EnterDomWarCopy));
            if (this.view) 
            {
                this.view.show();
                if (!this._isBossInfoUp) 
                {
                    (this.view as DominionWarCopyInfoPanel).updateInfos({"over": true});
                }
            }
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            Dispatcher.dispatchEvent(new DataEvent(EventName.LeaveDomWarCopy));
            if (this.view) 
            {
                this.view.hide();
            }
            if (this.myResultWin && !this.myResultWin.isHide) 
            {
                this.myResultWin.hide();
            }
            return;
        }

        /* internal */ /* var */_myResultWin: DominionWarResultWin;

        /* internal */ /* var */_isBossInfoUp: Boolean;
    }
